﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Threading;
using System.Diagnostics;

namespace Bohdan.Arch.Messaging
{
    public abstract class GeneralSingleThreadedSubscriber : GeneralSubscriber
    {
        protected volatile Thread _worker;

        public override void StartWorkersSync()
        {
            _worker = new Thread(new ThreadStart(WorkerThread));
            _worker.Priority = WorkerThreadPriority;
            _worker.Name = this.GetType().Name;
            try
            {
                _worker.Start();
            }
            catch
            {
                _worker = null;
                throw;                      // TODO: handle
            }
        }

        public override void EndWorkersSync()
        {
            _worker.Join();
        }
    }
}
